package com.bestcem.xm.user.mq.sender;

import com.bestcem.xm.user.mq.message.user.CreateUserMessage;
import com.bestcem.xm.user.mq.message.user.SmsMessage;
import com.bestcem.xm.user.mq.message.user.UpdateUserMessage;
import com.bestcem.xm.user.service.dto.order.RecordToOmDTO;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * 用户消息发送
 *
 * @author qiongyu.cui <qiongyu.cui@idiaoyan.com>
 * @version v1.0
 * @date 2022/3/9 18:44
 */
@Slf4j
//@Component("userMessageSender")
@Deprecated
public class UserMessageSender {
    //@Resource
    //private RabbitMqConstantConfig rabbitMqConstantConfig;
    //@Resource
    //private RabbitMessageSender rabbitMessageSender;

    /**
     * 创建用户发消息
     *
     * @param userId   用户id
     * @param groupIds 用户组id列表
     * @author cuiqiongyu <qiongyu.cui@idiaoyan.cn>
     * @date 2022/03/09 18:53
     */
    public void publishUserCreate(String userId, List<String> groupIds) {
        CreateUserMessage message = new CreateUserMessage(userId, groupIds);

        //try {
        //    // fanout模式直接发送给python
        //    rabbitMessageSender.sendMsg(rabbitMqConstantConfig.getAppFanoutExchange(), null,
        //            UserTopics.USER_CREATED, dto);
        //
        //    // topic模式发送给java
        //    rabbitMessageSender.sendMsg(rabbitMqConstantConfig.getAppBpDirectExchange(), rabbitMqConstantConfig.getAppBpRoutingKey(),
        //            UserTopics.USER_CREATED, dto);
        //
        //    if (log.isInfoEnabled()) {
        //        log.info("[User.Account] 发送mq消息成功, EXCHANGE_NAME={}, ROUTING_KEY={}, topic={}, mqMsg={}",
        //                rabbitMqConstantConfig.getAppFanoutExchange(), rabbitMqConstantConfig.getAppBpRoutingKey(),
        //                UserTopics.USER_CREATED, JSON.toJSONString(dto));
        //    }
        //} catch (Exception e) {
        //    log.error("[User.Account] 发送mq消息失败, EXCHANGE_NAME={}, ROUTING_KEY={}, topic={}, mqMsg={}",
        //            rabbitMqConstantConfig.getAppFanoutExchange(), rabbitMqConstantConfig.getAppBpRoutingKey(),
        //            UserTopics.USER_CREATED, JSON.toJSONString(dto));
        //}
    }

    /**
     * 更新用户信息
     *
     * @param userId   用户id
     * @param groupIds 用户组id列表
     * @author cuiqiongyu <qiongyu.cui@idiaoyan.cn>
     * @date 2022/03/09 19:07
     */
    public void publishUserUpdate(String userId, List<String> groupIds) {
        UpdateUserMessage message = new UpdateUserMessage(userId, groupIds);

        //try {
        //    // fanout模式直接发送给python
        //    rabbitMessageSender.sendMsg(rabbitMqConstantConfig.getAppFanoutExchange(), null,
        //            UserTopics.USER_UPDATED, dto);
        //
        //    // topic模式发送给java
        //    rabbitMessageSender.sendMsg(rabbitMqConstantConfig.getAppBpDirectExchange(), rabbitMqConstantConfig.getAppBpRoutingKey(),
        //            UserTopics.USER_UPDATED, dto);
        //
        //    if (log.isInfoEnabled()) {
        //        log.info("[User.Account] 发送mq消息成功, EXCHANGE_NAME={}, ROUTING_KEY={}, topic={}, mqMsg={}",
        //                rabbitMqConstantConfig.getAppFanoutExchange(), rabbitMqConstantConfig.getAppBpRoutingKey(),
        //                UserTopics.USER_UPDATED, JSON.toJSONString(dto));
        //    }
        //} catch (Exception e) {
        //    log.error("[User.Account] 发送mq消息失败, EXCHANGE_NAME={}, ROUTING_KEY={}, topic={}, mqMsg={}",
        //            rabbitMqConstantConfig.getAppFanoutExchange(), rabbitMqConstantConfig.getAppBpRoutingKey(),
        //            UserTopics.USER_UPDATED, JSON.toJSONString(dto));
        //}
    }

    /**
     * 更新用户联系方式mq
     *
     * @param userId
     * @param userIdList
     * @param userName
     * @param phone
     * @param email
     */
    public void publishUserUpdateContacts(String userId, List<String> userIdList, String userName, String phone, String email) {
        //UpdateUserContactsMessage dto = new UpdateUserContactsMessage();
        //dto.setUserId(userId);
        //dto.setUserIdList(userIdList);
        //dto.setUserName(userName);
        //dto.setPhone(phone);
        //dto.setEmail(email);
        //try {
        //    // topic模式发送给java
        //    rabbitMessageSender.sendMsg(rabbitMqConstantConfig.getAppBpDirectExchange(), rabbitMqConstantConfig.getAppBpRoutingKey(),
        //            UserTopics.USER_UPDATE_CONTACTS, dto);
        //
        //    if (log.isInfoEnabled()) {
        //        log.info("[User.Account] 发送mq消息成功, EXCHANGE_NAME={}, ROUTING_KEY={}, topic={}, mqMsg={}",
        //                rabbitMqConstantConfig.getAppFanoutExchange(), rabbitMqConstantConfig.getAppBpRoutingKey(),
        //                UserTopics.USER_UPDATE_CONTACTS, JSON.toJSONString(dto));
        //    }
        //} catch (Exception e) {
        //    log.error("[User.Account] 发送mq消息失败, EXCHANGE_NAME={}, ROUTING_KEY={}, topic={}, mqMsg={}",
        //            rabbitMqConstantConfig.getAppFanoutExchange(), rabbitMqConstantConfig.getAppBpRoutingKey(),
        //            UserTopics.USER_UPDATE_CONTACTS, JSON.toJSONString(dto));
        //}
    }

    /**
     * 统计用户数量
     *
     * @param orgId  组织id
     * @param amount 数量
     * @param ttype  类型
     * @author 林志剑 <zhijian.lin@idiaoyan.com>
     * @date 2022/03/09 19:07
     */
    public void publishQuotaConsumption(String orgId, Integer amount, String ttype) {
        //统计用户数量 await redis_mq.publish(topics.user_org_quota_consumption,{'org_id': str(org_id), 'amount': amount, 'ttype': 'user_total'})
        //QuotaConsumptionMessage dto = new QuotaConsumptionMessage(orgId, amount, ttype);
        //try {
        //    // fanout模式直接发送给python
        //    rabbitMessageSender.sendMsg(rabbitMqConstantConfig.getAppFanoutExchange(), null,
        //            UserTopics.USER_QUOTA_CONSUMPTION, dto);
        //
        //    // topic模式发送给java
        //    rabbitMessageSender.sendMsg(rabbitMqConstantConfig.getAppBpDirectExchange(), rabbitMqConstantConfig.getAppBpRoutingKey(),
        //            UserTopics.USER_QUOTA_CONSUMPTION, dto);
        //
        //    if (log.isInfoEnabled()) {
        //        log.info("[User.Account] 发送mq消息成功, EXCHANGE_NAME={}, ROUTING_KEY={}, topic={}, mqMsg={}",
        //                rabbitMqConstantConfig.getAppFanoutExchange(), rabbitMqConstantConfig.getAppBpRoutingKey(),
        //                UserTopics.USER_QUOTA_CONSUMPTION, JSON.toJSONString(dto));
        //    }
        //} catch (Exception e) {
        //    log.error("[User.Account] 发送mq消息失败, EXCHANGE_NAME={}, ROUTING_KEY={}, topic={}, mqMsg={}",
        //            rabbitMqConstantConfig.getAppFanoutExchange(), rabbitMqConstantConfig.getAppBpRoutingKey(),
        //            UserTopics.USER_QUOTA_CONSUMPTION, JSON.toJSONString(dto));
        //}
    }

    /**
     * 系统运营短信和邮件记录
     *
     * @return void
     * @author panyun <yun.pan@idiaoyan.com>
     * @date 2022/3/17 22:13
     */
    public void publishOmSmsSyc(SmsMessage message) {

        //try {
        //    // fanout模式直接发送给python
        //    rabbitMessageSender.sendMsg(rabbitMqConstantConfig.getAppFanoutExchange(), null,
        //            UserTopics.MSG_SYC, dto);
        //
        //    // topic模式发送给java
        //    rabbitMessageSender.sendMsg(rabbitMqConstantConfig.getAppBpDirectExchange(), rabbitMqConstantConfig.getAppBpRoutingKey(),
        //            UserTopics.MSG_SYC, dto);
        //
        //    if (log.isInfoEnabled()) {
        //        log.info("[User.Account] 发送mq消息成功, EXCHANGE_NAME={}, ROUTING_KEY={}, topic={}, mqMsg={}",
        //                rabbitMqConstantConfig.getAppFanoutExchange(), rabbitMqConstantConfig.getAppBpRoutingKey(),
        //                UserTopics.MSG_SYC, JSON.toJSONString(dto));
        //    }
        //} catch (Exception e) {
        //    log.error("[User.Account] 发送mq消息失败, EXCHANGE_NAME={}, ROUTING_KEY={}, topic={}, mqMsg={}",
        //            rabbitMqConstantConfig.getAppFanoutExchange(), rabbitMqConstantConfig.getAppBpRoutingKey(),
        //            UserTopics.MSG_SYC, JSON.toJSONString(dto));
        //}
    }

    /**
     * 达到限额通知
     *
     * @param event
     * @param orgId      公司id
     * @param totalQuota 总限额
     * @param quotaRate  限额比率
     * @return void
     * @author panyun <yun.pan@idiaoyan.com>
     * @date 2022/3/17 22:37
     */
    public void publishQuotaReached(String event, String orgId, Integer totalQuota, String quotaRate) {
        //QuotaReachedMessage dto = new QuotaReachedMessage(event,orgId,totalQuota, quotaRate);
        //
        //try {
        //    // fanout模式直接发送给python
        //    rabbitMessageSender.sendMsg(rabbitMqConstantConfig.getAppFanoutExchange(), null,
        //            UserTopics.USER_QUOTA_REACHED, dto);
        //
        //    // topic模式发送给java
        //    rabbitMessageSender.sendMsg(rabbitMqConstantConfig.getAppBpDirectExchange(), rabbitMqConstantConfig.getAppBpRoutingKey(),
        //            UserTopics.USER_QUOTA_REACHED, dto);
        //
        //    if (log.isInfoEnabled()) {
        //        log.info("[User.Account] 发送mq消息成功, EXCHANGE_NAME={}, ROUTING_KEY={}, topic={}, mqMsg={}",
        //                rabbitMqConstantConfig.getAppFanoutExchange(), rabbitMqConstantConfig.getAppBpRoutingKey(),
        //                UserTopics.USER_QUOTA_REACHED, JSON.toJSONString(dto));
        //    }
        //} catch (Exception e) {
        //    log.error("[User.Account] 发送mq消息失败, EXCHANGE_NAME={}, ROUTING_KEY={}, topic={}, mqMsg={}",
        //            rabbitMqConstantConfig.getAppFanoutExchange(), rabbitMqConstantConfig.getAppBpRoutingKey(),
        //            UserTopics.USER_QUOTA_REACHED, JSON.toJSONString(dto));
        //}
    }

    /**
     * 用户退出登录通知【系统商后台订阅】
     *
     * @param token token信息
     * @return void
     * @author cuiqiongyu <qiongyu.cui@idiaoyan.cn>
     * @date 2022/05/26 18:01
     */
    public void publishUserLogout(String token) {
        //UserLogoutMessage dto = new UserLogoutMessage(token);
        //
        //try {
        //    // topic模式发送给java系统商后台订阅
        //    rabbitMessageSender.sendMsg(rabbitMqConstantConfig.getAppBpDirectExchange(), rabbitMqConstantConfig.getAppBpRoutingKey(),
        //            UserTopics.OM_XM_TOKEN_LOGOUT, dto);
        //
        //    if (log.isInfoEnabled()) {
        //        log.info("[User.Logout] 发送mq消息成功, EXCHANGE_NAME={}, ROUTING_KEY={}, topic={}, mqMsg={}",
        //                rabbitMqConstantConfig.getAppFanoutExchange(), rabbitMqConstantConfig.getAppBpRoutingKey(),
        //                UserTopics.OM_XM_TOKEN_LOGOUT, JSON.toJSONString(dto));
        //    }
        //} catch (Exception e) {
        //    log.error("[User.Logout] 发送mq消息失败, EXCHANGE_NAME={}, ROUTING_KEY={}, topic={}, mqMsg={}",
        //            rabbitMqConstantConfig.getAppFanoutExchange(), rabbitMqConstantConfig.getAppBpRoutingKey(),
        //            UserTopics.OM_XM_TOKEN_LOGOUT, JSON.toJSONString(dto));
        //}
    }

    public void recordToOm(RecordToOmDTO recordToOmDTO) {
        //if (Objects.isNull(recordToOmDTO)) {
        //    return;
        //}
        //RecordToOmMessage dto = new RecordToOmMessage();
        //BeanUtils.copyProperties(recordToOmDTO, dto);
        //
        //try {
        //    // topic模式发送给java
        //    rabbitMessageSender.sendMsg(rabbitMqConstantConfig.getAppBpDirectExchange(), rabbitMqConstantConfig.getAppBpRoutingKey(),
        //            UserTopics.MSG_SYC, dto);
        //
        //    if (log.isInfoEnabled()) {
        //        log.info("[recordToOm] 发送mq消息成功, EXCHANGE_NAME={}, ROUTING_KEY={}, topic={}, mqMsg={}",
        //                rabbitMqConstantConfig.getAppFanoutExchange(), rabbitMqConstantConfig.getAppBpRoutingKey(),
        //                UserTopics.MSG_SYC, JSON.toJSONString(dto));
        //    }
        //} catch (Exception e) {
        //    log.error("[recordToOm] 发送mq消息失败, EXCHANGE_NAME={}, ROUTING_KEY={}, topic={}, mqMsg={}",
        //            rabbitMqConstantConfig.getAppFanoutExchange(), rabbitMqConstantConfig.getAppBpRoutingKey(),
        //            UserTopics.MSG_SYC, JSON.toJSONString(dto));
        //}
    }


    /**
     * 租户发生高级管理员角色账号变动
     *
     * @param orgId
     * @return void
     * @author Linzhijian <zhijian.lin@idiaoyan.com>
     * @date 2022/06/18 17:57
     */
    public void publishSeniorRoleChanged(String orgId) {
        //SeniorRoleChangeMessage dto = new SeniorRoleChangeMessage(orgId);
        //
        //try {
        //    // fanout模式直接发送给python
        //    rabbitMessageSender.sendMsg(rabbitMqConstantConfig.getAppFanoutExchange(), null,
        //            UserTopics.USER_ORG_SENIOR_ROLE_CHANGED, dto);
        //
        //    if (log.isInfoEnabled()) {
        //        log.info("[SeniorRoleChanged] 发送mq消息成功, EXCHANGE_NAME={}, ROUTING_KEY={}, topic={}, mqMsg={}",
        //                rabbitMqConstantConfig.getAppFanoutExchange(), rabbitMqConstantConfig.getAppBpRoutingKey(),
        //                UserTopics.USER_ORG_SENIOR_ROLE_CHANGED, JSON.toJSONString(dto));
        //    }
        //} catch (Exception e) {
        //    log.error("[SeniorRoleChanged] 发送mq消息失败, EXCHANGE_NAME={}, ROUTING_KEY={}, topic={}, mqMsg={}",
        //            rabbitMqConstantConfig.getAppFanoutExchange(), rabbitMqConstantConfig.getAppBpRoutingKey(),
        //            UserTopics.USER_ORG_SENIOR_ROLE_CHANGED, JSON.toJSONString(dto));
        //}
    }
}
